package devaluator.functionality;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public abstract class Parser {
	/*
	 * stores file paths of all java files 
	 */
	protected List<String> filePaths = new ArrayList<String>(); 
	protected File root;
	
	/*
	 * Pattern for matching: 
	 * regular classes, interfaces, generic 
	 */
	final String modifier= "(public|public(\\n*)(\\s+)abstract|private|protected)";
	final String regexIface= modifier+"((\\n*)(\\s+)interface(\\s+))(([a-zA-Z_$][\\w$]*)(\\s*)((\\{)))";
	final String theRest= "(((\\n*)(\\s+)class(\\s+))([a-zA-Z_$][\\w$]*)(\\s*)((\\{)|" +
					  "(((extends|implements)(\\s+)([a-zA-Z_$][\\w$]*))((\\s*)(\\{)))))|"+regexIface;
	final String regexClass= modifier+theRest;
	
	final String userPack= "(\\s*)(package)(\\s+)([^=])(.*)(;)";
	final String impPack= "(\\s*)(import)(\\s+)([^=])(.*)(;)";
    final String comPack= userPack+"|"+impPack; 
	
	
	 /**
     * Recursive function to descend into the directory tree and find all the files 
     * that end with ".java"
     * @param dir A file object defining the top directory
     * @return adds to the filsePaths list 
     **/   
	protected void walk(File dir) {
		String pattern = ".java"; 
		File listFile[] = dir.listFiles();
	        
		if(listFile != null) {
			for(int i=0; i<listFile.length; i++) {
				if(listFile[i].isDirectory()) {
					walk(listFile[i]);
					} 
				else{
					if(listFile[i].getName().endsWith(pattern)) {
						filePaths.add(listFile[i].getAbsolutePath()); 
						}
					}
				}
			}
		}
	
	public abstract List<String> match(); 


}
